#include "gmap.h"

GMap::GMap(QWidget *parent)  :
        QWebView(parent) {
    settings()->setAttribute(QWebSettings::JavascriptEnabled,true);
}

void GMap::setCenter(QPointF i_point) {
    QString l_js_command = QString("setCenter(new google.maps.LatLng(%1, %2))")
                           .arg(i_point.x())
                           .arg(i_point.y());
    toJavaScript(l_js_command);
}

void GMap::setZoom(int i_zoom) {
    QString l_js_command = QString("setZoom(%1)")
                           .arg(i_zoom);
    toJavaScript(l_js_command);
}

void GMap::addPoint(QPointF i_point) {
    QString l_js_command = QString("addPoint(new google.maps.LatLng(%1, %2))")
                           .arg(i_point.x())
                           .arg(i_point.y());
    toJavaScript(l_js_command);
}

void GMap::delPoint() {
    toJavaScript("delPoint()");
}

void GMap::addPolyline() {
    toJavaScript("setPL()");
}

void GMap::toJavaScript(QString i_str) {
    page()->mainFrame()->evaluateJavaScript( i_str );
}
